package com.winshare.saleAssistant.controller;


import com.winshare.saleAssistant.domain.dto.req.BaseIdDTO;
import com.winshare.saleAssistant.domain.dto.req.ProductInfoVersionCreateDTO;
import com.winshare.saleAssistant.domain.dto.req.ProductInfoVersionQueryDTO;
import com.winshare.saleAssistant.domain.dto.req.ProductInfoVersionUpdateDTO;
import com.winshare.saleAssistant.service.ProductInfoVersionService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/product-info/version")
@CrossOrigin
@Api(value = "版本信息", description = "版本信息")
public class ProductInfoVersionController {

    private final ProductInfoVersionService productInfoVersionService;

    public ProductInfoVersionController(ProductInfoVersionService productInfoVersionService) {
        this.productInfoVersionService = productInfoVersionService;
    }

    @PostMapping("/save")
    @ApiModelProperty(value = "新增版本信息",notes = "新增版本信息")
    public LogicResponse save(@RequestBody @Validated ProductInfoVersionCreateDTO productInfoVersionCreateDTO) {
        productInfoVersionService.saveProductInfoVersion(productInfoVersionCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改产品信息",notes = "修改产品信息")
    public LogicResponse update(@RequestBody @Validated ProductInfoVersionUpdateDTO productInfoVersionUpdateDTO) {
        productInfoVersionService.updateProductInfoVersion(productInfoVersionUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "",notes = "")
    public LogicResponse delete(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        productInfoVersionService.deleteProductInfoVersion(baseIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个版本详情",notes = "获取单个版本详情")
    public LogicResponse getProductInfoVersionDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(productInfoVersionService.getProductInfoVersionDetail(baseIdDTO));
    }

    @PostMapping("/list")
    public LogicResponse getProductInfoVersionList(@RequestBody @Validated
                                  ProductInfoVersionQueryDTO productInfoVersionQueryDTO) {
        return LogicResponse.success(productInfoVersionService.getProductInfoVersionPage(productInfoVersionQueryDTO));
    }
}
